# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=mautrix-discord
pkgver=0.6.4
pkgrel=0
pkgdesc="Matrix-Discord puppeting bridge"
url="https://go.mau.fi/mautrix-discord/"
arch="all"
license="AGPL-3.0-or-later"
depends="lottieconverter"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/discord/archive/v$pkgver.tar.gz
	mautrix-discord.initd
	mautrix-discord.confd
	default-log-dir.patch
"
builddir="$srcdir/discord-$pkgver"
options="net"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	go build
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-discord \
		-t "$pkgdir"/usr/bin/
	install -Dm644 example-config.yaml \
		-t "$pkgdir"/etc/mautrix-discord/

	install -Dm755 "$srcdir"/mautrix-discord.initd \
		"$pkgdir"/etc/init.d/mautrix-discord
	install -Dm644 "$srcdir"/mautrix-discord.confd \
		"$pkgdir"/etc/conf.d/mautrix-discord

	install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

sha512sums="
cfcb5653d002c33f3498a65d7f6e507c1465b8ef767b672db770f44eaf59887246896e2f4149164e610a91af1418646eca77e571a85b0fdaeddc3131e589429e  mautrix-discord-0.6.4.tar.gz
772c39fd22eccf4116ebe0b496a055a2807ef3b500a7bbc8838e2fc1fef8b05e20be80b7e7b515304914ca244349093a21cdcf42b2e6dd0bcbd45fef3358fd89  mautrix-discord.initd
46c472289880a631389dbc7f40062858f7a11e2987f1183cb16d426aa50f57d4b57e4857e4f9852b1c930fc03ccf304bcd27a452681a570e97ec8174808cbf01  mautrix-discord.confd
f2317ccd91959c2d6b6937ab09bbcb5e2472847c5b880c4a37a4dd96784705a503a5cfcb183017656d716dfceabbc55c33d1083f1cb26c7964bf6dd4dd57f364  default-log-dir.patch
"
